package com.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: leetcode
 * @author: jzhou
 * @date: 2022-11-16 12:03
 * @version: 1.0
 * @description: 找到所有数组中消失的数字
 **/
public class FindDisappearedNumbers {
    public static void main(String[] args) {
        int[] nums = {4,3,2,7,8,2,3,1};
//        int[] nums = {1,1};
        System.out.println(findDisappearedNumbers(nums));
    }

    static public List<Integer> findDisappearedNumbers(int[] nums) {
        int length = nums.length;
        for (int num : nums) {
            int index = (num - 1) % length;
            nums[index] += length;
        }

        List<Integer> list = new ArrayList<>();

        for (int i = 0; i < length; i++) {
            if (nums[i] <= length){
                list.add(i + 1);
            }
        }

        return list;
    }
}
